package com.lh.blogResource.controller.admin;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.extension.api.R;
import com.lh.blogCommon.result.LhR;
import com.lh.blogCommon.util.PageUtils;
import com.lh.blogResource.entity.ResourceTypeEntity;
import com.lh.blogResource.service.ResourceTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author lh0510
 * @email lh0510@gmail.com
 * @date 2021-03-09 10:31:46
 */
@Api(description = "资源分类管理")
@RestController
@RequestMapping("/admin/blogResource/resourcetype")
public class ResourceTypeController {
    @Autowired
    private ResourceTypeService resourceTypeService;

    /**
     * 列表
     */
    @ApiOperation("列表")
    @GetMapping("/list")
    public LhR list(@RequestParam Map<String, Object> params){
        PageUtils page = resourceTypeService.queryPage(params);

        return LhR.ok().data("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("信息")
    @GetMapping("/info/{resourcetypeId}")
    public LhR info(@PathVariable("resourcetypeId") String resourcetypeId){
		ResourceTypeEntity resourceType = resourceTypeService.getById(resourcetypeId);

        return LhR.ok().data("resourceType", resourceType);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @PostMapping("/save")
    public LhR save(@RequestBody ResourceTypeEntity resourceType){
		resourceTypeService.save(resourceType);

        return LhR.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PutMapping("/update")
    public LhR update(@RequestBody ResourceTypeEntity resourceType){
		resourceTypeService.updateById(resourceType);

        return LhR.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public LhR delete(@RequestBody String[] resourcetypeIds){
		resourceTypeService.removeByIds(Arrays.asList(resourcetypeIds));

        return LhR.ok();
    }

}
